package com.lwp.test.utils;

import com.lwp.test.aoptest.dto.OneEvent;

public class ThreadUtils {

    private static final ThreadLocal<Long> timeThreadLocal = new ThreadLocal();

    public static final ThreadLocal<OneEvent> EVENT_THREAD_LOCAL = new ThreadLocal();


    public static long startTime() {
        long startTime = System.currentTimeMillis();
        timeThreadLocal.set(startTime);
        return startTime;
    }

    /**
     * @return 返回 endTime -  startTime 的时间 毫秒数
     */
    public static long endTime() {
        if (timeThreadLocal.get() == null) {
            throw new RuntimeException("endTime() 和 startTime() 需要配对使用");
        }
        long endTime = System.currentTimeMillis();
        long costTime = endTime - timeThreadLocal.get();
        timeThreadLocal.set(null);
        return costTime;
    }
}
